﻿using System;
using System.Collections.Generic;
using System.Windows;
using Infragistics.Controls.Editors;
using VNet.VisiSuite.Common;
using VNet.VisiSuite.Controls;
using VNet.VisiSuite.VisiBoard.Controls;
using VNet.VisiSuite.VisiBoard.Models;
using VNet.VisiSuite.VisiBoard.ViewModels;
using VNet.VisiSuite.VisiBoard.Dal.EntityClasses;

namespace VNet.VisiSuite.VisiBoard.Views
{
    public partial class ChangeoverDialogView : VisiDialog
    {
        private ChangeoverDialogViewModel _model;
        private bool _visibox_event;

       
        public ChangeoverDialogView(bool visibox_event)
        {
            InitializeComponent();
            var menu_items = new List<VNetMenuItem>();
            menu_items.Add(new VNetMenuItem(null, "OK", CommonConstants.VNetIcon.AppbarCheck, VNetMenuItemType.WhiteBackgroundTheme, onOK));
            menu_items.Add(new VNetMenuItem(null, "Cancel", CommonConstants.VNetIcon.AppbarClose, VNetMenuItemType.WhiteBackgroundTheme, onCancel));
            _menu.Icons = menu_items;
            _menu.Icons[0].IsEnabled = false;
            _bottom_bar.Icons = new List<VNetMenuItem>
            {
                new VNetMenuItem(null, "Input Keyboard",CommonConstants.VNetIcon.AppbarInputKeyboard,VNetMenuItemType.WhiteBackgroundTheme, onKeyboard)
            };

            _model = DataContext as ChangeoverDialogViewModel;
            _visibox_event = visibox_event;
        }

        private void VisiDialog_Loaded(object sender, RoutedEventArgs e)
        {
            _operator_id.Focus();
            RaiseInputKeyboardClick();
        }

        public dynamic SelectedProductionPlan
        {
            get
            {
                return _model.SelectedProductionPlan;
            }
        }

        public int? OperatorId
        {
            get
            {
                return _model.Operator != null ? _model.Operator.OperatorId : (int?)null;
            }
        }

        public bool IsVisiBoxEvent
        {
            get { return _visibox_event; }
        }

        private void onKeyboard()
        {
            RaiseInputKeyboardClick();
        }

        private void onOK()
        {
            if (_model.validate())
            {
                Cancelled = false;
                close();
            }
        }

        private void onCancel()
        {
            Cancelled = true;
            close();
        }

        private void production_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (_combo_production_plan != null)
            {
                _menu.Icons[0].IsEnabled = (_combo_production_plan.SelectedItem != null);
                _model.SelectedProductionPlan = (dynamic) _combo_production_plan.SelectedItem;
            }
        }

    }
}
